home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Apple Script
/
OSAX
/
Mount Volume
/
ZoneList.c
< prev
next >
Wrap
Text File
|
1993-10-29
|
3KB
|
130 lines
#ifndef __APPLETALK__
#include <Appletalk.h>
#endif
#ifndef __ERRORS__
#include <Errors.h>
#endif
#ifndef __APPLEEVENTS__
#include <AppleEvents.h>
#endif
#ifndef __PLSTRINGFUNCS__
#include <PLStringFuncs.h>
#endif
#ifndef __MEMORY__
#include <Memory.h>
#endif
#ifndef __STRING__
#include <String.h>
#endif
void SetReturnValue(AppleEvent *result, Ptr theText);
void SetErrorValue(AppleEvent *result, Ptr theText, OSErr error);
void ParseBuffer(char *stuff, AEDescList theList, short);
OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString);
pascal OSErr GetObjectList(AppleEvent *in, AppleEvent *out, long);
pascal OSErr GetObjectList(AppleEvent *in, AppleEvent *out, long)
{
MPPParamBlock pb;
EntityName entity;
char buffer[4000];
AEDescList theList;
OSErr error;
Str32 zoneName;
Str32 typeName;
error = AECreateList(nil, 0, false, &theList);
if (error) return error;
error = Get1Parameter(in, 'TYPE', 31, typeName);
if (error)
{
typeName[0] = 1;
typeName[1] = '=';
error = noErr;
}
error = Get1Parameter(in, 'ZONE', 31, zoneName);
if (error)
{
zoneName[0] = 1;
zoneName[1] = '*';
error = noErr;
}
NBPSetEntity((Ptr)&entity, "\p=", typeName, zoneName);
pb.NBPinterval = 3;
pb.NBPcount = 3;
pb.NBPentityPtr = (Ptr)&entity;
pb.NBPretBuffSize = 4000;
pb.NBPretBuffPtr = buffer;
pb.NBPmaxToGet = 40;
error = PLookupName((MPPPBPtr) &pb, false);
if (!error)
{
if (pb.NBPnumGotten)
{
ParseBuffer(buffer, theList, pb.NBPnumGotten);
}
else
{
char c = 0;
AEPutPtr(&theList, 0, typeChar, &c, 1);
}
AEPutParamDesc(out, keyDirectObject, &theList);
}
else
{
SetErrorValue(out, "Network Error!",error);
}
AEDisposeDesc(&theList);
return error;
}
void ParseBuffer(char *stuff, AEDescList theList, short numItems)
{
OSErr error;
EntityName theEntity;
AddrBlock theAddress;
short count = numItems;
do
{
error = NBPExtract((Ptr) stuff, numItems, count, &theEntity, &theAddress);
p2cstr((char *) &theEntity);
error = AEPutPtr(&theList, 0, typeChar, (char *)&theEntity, strlen((char *)&theEntity));
} while (--count && !error);
}
OSErr Get1Parameter(AppleEvent *in, OSType type, short size, StringPtr theString)
{
DescType theType;
OSErr error;
Size paramSize;
error = AESizeOfParam(in, type, &theType, ¶mSize);
if (error) goto exit;
theString[0] = paramSize;
error = AEGetParamPtr(in, type, typeChar, &theType, (Ptr) &(theString[1]), size, ¶mSize);
if (error) goto exit;
// c2pstr((char *)theString);
exit:
return error;
}
void SetReturnValue(AppleEvent *result, Ptr theText)
{
AEPutParamPtr(result, keyDirectObject, typeChar, theText, strlen(theText));
}
void SetErrorValue(AppleEvent *result, Ptr theText, OSErr error)
{
AEPutParamPtr(result, keyErrorNumber, typeShortInteger, (Ptr) &error, sizeof(short));
AEPutParamPtr(result, keyErrorString, typeChar, theText, strlen(theText));
}